package com.syx.friend.Rabbit;

import com.syx.api.Model.DTO.JudgeSubmitDTO;
import com.syx.commoncore.Constant.RabbitMQConstants;
import com.syx.commoncore.enums.Resultcode;
import com.syx.security.Exception.ServiceException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
@Slf4j
public class JudgeProducer {
    @Autowired
    private RabbitTemplate rabbitTemplate;
    public void produceMsg(JudgeSubmitDTO judgeSubmitDTO) {
        try {
            rabbitTemplate.convertAndSend(RabbitMQConstants.OJ_WORK_QUEUE,
                    judgeSubmitDTO);
        } catch (Exception e) {
            log.error("⽣产者发送消息异常", e);
            throw new ServiceException(Resultcode.FAILED_RABBIT_PRODUCE);
        }
    }
}
